package cn.com.colasoft.generics;

import com.google.common.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 通过Guava获取泛型类型
 * </p>
 *
 * @author jian.li5
 * @date 2019/7/2
 */
public class GuavaTypeToken {
    public static void main(String[] args) {
        TypeToken<HashMap<String, Integer>> typeToken = new TypeToken<HashMap<String, Integer>>() {};
        Type type = typeToken.getType();
        System.out.println(type);
        System.out.println(typeToken.getRawType());
        System.out.println(typeToken.getSupertype(Map.class));

        System.out.println("--------------------");
        TypeToken<Apple<String, Integer>> typeToken1 = new TypeToken<Apple<String, Integer>>() {};
        System.out.println(typeToken1);
        System.out.println(typeToken1.getRawType());
        System.out.println(typeToken1.getSupertype(Fruit.class));
        System.out.println(typeToken1.getSupertype(Apple.class));
    }
}

class Fruit<T> {}
class Apple<T,V> extends Fruit<T> {}
